﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySql.Data.MySqlClient;

namespace StockAdmin.Dao
{
    public class SqlHeper
    {
        public static  MySqlConnection connection;
        private string server = "aws.sly.io";
        private string database;
        private string uid;
        private string password;
        public static readonly string connectionString = "SERVER=" + "aws.sly.io" + ";" + "DATABASE=" + "api0804" + ";" + "UID=" + "api0804" + ";" + "PASSWORD=" + "zaq12wsx" + ";";

        //Initialize values
        private void Initialize()
        {
            server = "aws.sly.io";
            database = "api0804";
            uid = "api0804";
            password = "zaq12wsx";
            

            
        }


        //open connection to database
        public static bool OpenConnection()
        {
            try
            {
                connection = new MySqlConnection(connectionString);
                connection.Open();
                return true;
            }
            catch (MySqlException ex)
            {
                //When handling errors, you can your application's response based on the error number.
                //The two most common error numbers when connecting are as follows:
                //0: Cannot connect to server.
                //1045: Invalid user name and/or password.
                switch (ex.Number)
                {
                    case 0:
                        break;

                    case 1045:
                        break;
                }
                return false;
            }
        }

        //Close connection
        public static bool CloseConnection()
        {
            try
            {
                connection.Close();
                return true;
            }
            catch (MySqlException ex)
            {
                return false;
            }
        }
    }
}